/**
 * KopsoxApplicationServices
 * Copyright (C) 2010 Free Software Foundation, Inc. <http://fsf.org/>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.kopsox.services.security;

import java.io.Serializable;

/**
 * This class defines a role which can be mapped to a KopsoxPrincipal.
 * 
 * @author Konrad Renner
 *
 */
public class Role implements Serializable {

	/**
	 * serialVersionUID = -6627447230400694689L
	 */
	private static final long serialVersionUID = -6627447230400694689L;
	
	private final String name;
	private final Object roleDefinition;
	private final int hashCode;
	
	public Role(String name, Object roleDefinition) {
		this.name = name;
		this.roleDefinition = roleDefinition;
		
		int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		hashCode = prime * result + ((roleDefinition == null) ? 0 : roleDefinition.hashCode());
		
	}
	
	@Override
	public String toString() {
		
		StringBuilder sb = new StringBuilder();
		sb.append("Role [name=");
		sb.append(name);
		sb.append(", roleDefinition=");
		sb.append(roleDefinition);
		sb.append(']');
		
		return sb.toString();
	}

	public String getName() {
		return name;
	}

	public Object getRoleDefinition() {
		return roleDefinition;
	}

	@Override
	public int hashCode() {
		return this.hashCode;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Role other = (Role) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (roleDefinition == null) {
			if (other.roleDefinition != null)
				return false;
		} else if (!roleDefinition.equals(other.roleDefinition))
			return false;
		return true;
	}
}
